package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbLevel;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.common.IIDService;
import com.ag.zlw.service.LevelService;

/**
 * 经典案例级别
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("LevelAction")
public class LevelAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "LevelService")
	private LevelService service;
	private List<TbLevel> levelList;
	private String message;
	private String levelId;
	private String levelName;
	TbLevel tbLevel = new TbLevel();

	private String IDs;
	@Resource(name = "iDServiceImpl")
	private IIDService idservice;

	public String find() {
		try {
			levelList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbLevel.setLevelId(levelId);
		try {
			service.delete(tbLevel);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		IDs = (String) idservice.findTablePK(IDUtil.TB_LEVEL);
		tbLevel.setLevelId(IDs);
		tbLevel.setLevelName(levelName);
		tbLevel.setA(IDUtil.PRESERVE);
		try {
			service.save(tbLevel);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbLevel.setLevelId(levelId);
		tbLevel.setLevelName(levelName);
		tbLevel.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbLevel);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}

	public String getLevelId() {
		return levelId;
	}

	public void setLevelId(String levelId) {
		this.levelId = levelId;
	}

	public String getLevelName() {
		return levelName;
	}

	public void setLevelName(String levelName) {
		this.levelName = levelName;
	}

	public void setLevelList(List<TbLevel> levelList) {
		this.levelList = levelList;
	}

	public List<TbLevel> getLevelList() {
		return levelList;
	}
}
